#!/bin/bash
rm -f /project/bin/game_server
rm -f /project/bin/fastway
declare go_build_args="-ldflags=-s -gcflags \"-N -l\" -tags \"debug\" "
export CGO_CFLAGS=" -std=gnu99 -I/usr/local/luajit/include/luajit-2.1"
export CGO_LDFLAGS=" -L/usr/local/luajit/lib -lluajit-5.1 -lm -ldl"

function goinstall(){
	pkgpath=$1 
	eval "go install -i $go_build_args $pkgpath"
}


goinstall github.com/ChaimHong/gobuf 
goinstall fastway 
goinstall ppserver 
goinstall nickname_server 
goinstall gm_api
goinstall online
goinstall monitor
goinstall game_tools/dump_sql
goinstall client_log
#
#cd server
find /go -name "*.fast.go" -exec rm -f {} \;
find /go -name "*.link.go" -exec rm -f {} \;
find /go -name "*.fastbin.go" -exec rm -f {} \;
find /go -name "*.fastapi.go" -exec rm -f {} \;

goinstall game_server

SluaProtoDir=/client/Assets/StreamingAssets/Scripts/Protos
SluaDataDir=/client/Assets/StreamingAssets/Scripts/Datas
RobotProtoDir=/go/src/game_robot/api
if [ ! -d "$RobotProtoDir" ]; then
	mkdir "$RobotProtoDir"
fi

game_server -generate=true  -config_dir='/go/bin/config/' -etcd_endpoints='172.17.0.1:2379' -slua.proto.dir=$SluaProtoDir -slua.data.dir=$SluaDataDir -robot.proto.dir=$RobotProtoDir -build.type=$buildTags

#cp lua files
cd /go
if [ ! -d "bin/lua" ]; then
  mkdir bin/lua
fi
rm -rf bin/lua/*
cp  -R /client/Assets/StreamingAssets/Scripts/* bin/lua/
find bin/lua/ -name '*.meta' -exec rm {} \;

#build lua lib
cd lib/
./make.sh
cd -
mv lib/MersenneTwister.so ./bin/lua

cd ..

goinstall game_server
goinstall game_robot